package com.github.cyf.config;

import com.github.cyf.common.exception.BizException;
import com.github.cyf.common.module.Rs;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类：定义了多个异常处理类，越小的优先执行，默认为最大
 * @author chenyifan
 * @create 2024-05-24 19:09
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Rs exception(Exception e) {
        log.error("系统异常：", e);
        return Rs.error("系统异常");
    }

    @ExceptionHandler(BizException.class)
    public Rs handler(BizException e) {
        log.error("业务异常：", e);
        return Rs.error(e.getMessage());
    }
}